<!DOCTYPE html>
<script src="../js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/ztree/jquery.ztree.all-3.5.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="../js/easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="../js/easyui/themes/icon.css" />
<link rel="stylesheet" type="text/css" href="../js/ztree/zTreeStyle.css" />
<script type="text/javascript">
	$(function() {
		$("#czbk").click(function() {
			$('#mytabs').tabs('add', {
				title: '传智播客',
				content: '传智播客教育培训',
				closable: true,

				tools: [{

					iconCls: 'icon-mini-refresh',

					handler: function() {

						alert('refresh');

					}

				}]

			});
		});
	});

	// 页面加载后执行
	$(function() {
		// 1、 进行ztree菜单设置 
		var setting = {
			data: {
				simpleData: {
					enable: true // 支持简单json数据格式
				}
			},
			callback: {
				onClick: function(event, treeId, treeNode, clickFlag) {
					var content = '<div style="width:100%;height:100%;overflow:hidden;">' + '<iframe src="' +
						treeNode.page +
						'" scrolling="auto" style="width:100%;height:100%;border:0;"></iframe></div>';
					// 问题一：没有page树形菜单，不打开选项卡
					if(treeNode.page != undefined && treeNode.page != "") {
						// 问题二：如果选项卡已经打开，选中 
						if($("#mytabs").tabs('exists', treeNode.name)) {
							// 选中选项卡
							$("#mytabs").tabs('select', treeNode.name);
						} else {
							// 如果没有打开，添加选项卡 
							$("#mytabs").tabs('add', {
								title: treeNode.name,
								content: content,
								closable: true
							});
						}
					}

				}
			}
		};

		// 2、提供ztree树形菜单数据 
		var zNodes = [{
				id: 1,
				pId: 0,
				name: "父节点一"
			},
			{
				id: 2,
				pId: 0,
				name: "父节点二"
			},
			{
				id: 11,
				pId: 1,
				name: "子节点一"
			},
			{
				id: 12,
				pId: 1,
				name: "子节点二"
			},
			{
				id: 13,
				pId: 2,
				name: "传智播客",
				page: "http://www.itcast.cn"
			},
			{
				id: 14,
				pId: 2,
				name: "百度",
				page: "https://www.baidu.com"
			}

		];

		// 3、生成菜单
		$.fn.zTree.init($("#tree"), setting, zNodes);
		
		// 设置全局变量 保存当前正在右键的tabs 标题 
		var currentRightTitle  ;

		// 为选项卡，添加右键菜单 
				$('#mytabs').tabs({
					onContextMenu : function(e,title,index){
						currentRightTitle = title ; 
						$('#mm').menu('show', { 
							left: e.pageX,
							top: e.pageY 
						});
						e.preventDefault(); // 禁用原来的右键效果 
					}
				});
				
				$('#mm').menu({ 
					onClick:function(item){ 
						if(item.name==='Close'){
							$('#mytabs').tabs('close',currentRightTitle);
						}else if(item.name === 'CloseOthers'){
							var tabs = $('#mytabs').tabs('tabs');
							$(tabs).each(function(){
								if($(this).panel('options').title != currentRightTitle){
									$('#mytabs').tabs('close',$(this).panel('options').title);
								}
							});
						}else if(item.name === 'CloseAll'){
							var tabs = $('#mytabs').tabs('tabs');
							$(tabs).each(function(){
								
									$('#mytabs').tabs('close',$(this).panel('options').title);
								
							});
						}
					} 
				})
				
				$.messager.show({
					title: "标题",
					msg : "减价大促销 ， <a href='#'>请猛戳这里</a>",
					timeout: 5000 // 5秒后自动消失
				});


	});
</script>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body class="easyui-layout">

		<div data-options="region:'north',title:'传智播客',split:true" style="height:100px;"></div>

		<div data-options="region:'south',title:'公司信息',split:true" style="height:100px;"></div>

		<div data-options="region:'west',title:'菜单导航',split:true" style="width:200px;">

			<!--折叠面板-->
			<div id="myaccordion" class="easyui-accordion" data-options="fit:true" style="width:300px;height:200px;">

				<div title="基本功能" data-options="iconCls:'icon-save'" style="overflow:auto;padding:10px;">
					<a href="javascript:void(0)" id="czbk">传智播客</a>
				</div>

				<div title="系统管理" data-options="iconCls:'icon-reload',selected:true" style="padding:10px;">

					<!--通过ztree插件,制作树菜单-->
					<ul id="tree" class="ztree" style="width:260px; overflow:auto;"></ul>

				</div>
			</div>

		</div>

		<div data-options="region:'center'" style="padding:5px;background:#eee;">

			<!--选项卡面板-->
			<div id="mytabs" class="easyui-tabs" data-options="fit:true" style="width:500px;height:250px;">

				<div title="消息中心1" style="padding:20px;display:none;">tab1 </div>

				<div title="消息中心2" data-options="closable:true" style="overflow:auto;padding:20px;display:none;">tab2 </div>

				<div title="消息中心3" data-options="iconCls:'icon-reload',closable:true,selected:true" style="padding:20px;display:none;">tab3 </div>

			</div>

		</div>

		<!-- 菜单 初始化都是隐藏的-->
		<div id="mm" class="easyui-menu" style="width:120px;">
			<div data-options="name:'Close'">关闭当前窗口</div>
			<div data-options="name:'CloseOthers'">关闭其它窗口</div>
			<div class="menu-sep"></div>
			<div data-options="iconCls:'icon-cancel',name:'CloseAll'">关闭全部窗口</div>
		</div>

	</body>

</html>